package com.wteam.dragon.shop.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wteam.dragon.shop.pojo.bean.ProductAttribute;
import com.wteam.dragon.shop.service.ProductAttributeService;
import com.wteam.dragon.system.aop.log.log.Log;
import com.wteam.dragon.system.basebean.bean.ResultMessage;
import com.wteam.dragon.system.basebean.vo.PageVo;
import com.wteam.dragon.system.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

/**
 * @Author 陈晓辉
 * @Date 2020/6/29 16:49
 */

@RestController
@RequiredArgsConstructor
@Api(tags = "商品属性和参数")
@RequestMapping("productAttribute")
public class ProductAttributeController {
    private final ProductAttributeService productAttributeService;

    @Log("添加商品属性参数")
    @ApiOperation("添加商品属性参数")
    @PostMapping("addProductAttribute")
    @PreAuthorize("@el.check('addProductAttribute')")
    public ResultMessage addProductType(ProductAttribute productAttribute){
        return productAttributeService.addProductAttribute(productAttribute);
    }

    @Log("删除商品属性参数")
    @ApiOperation("删除商品属性参数")
    @DeleteMapping("delProductAttribute")
    @PreAuthorize("@el.check('delProductAttribute')")
    public ResultMessage delProductAttribute(@RequestParam("ids") Set<Long> ids){
        return productAttributeService.delProductAttribute(ids);
    }

    @Log("更改商品属性参数")
    @ApiOperation("更改商品属性参数")
    @PutMapping("editProductAttribute")
    @PreAuthorize("@el.check('editProductAttribute')")
    public ResultMessage editProductAttribute(ProductAttribute productAttribute){
        return productAttributeService.editProductAttribute(productAttribute);
    }

    @Log("分页获得商品属性参数")
    @ApiOperation("分页获得商品属性参数")
    @GetMapping("pageProductAttribute")
    @PreAuthorize("@el.check('pageProductAttribute')")
    public ResultMessage pageProductAttribute(PageVo<ProductAttribute> pageVo, Integer productTypeId, Integer type){
        Page<ProductAttribute> page = BeanUtil.fromPage(pageVo);
        return productAttributeService.pageProductAttribute(page, productTypeId, type);
    }

    @Log("通过id获得商品属性参数详情")
    @ApiOperation("通过id获得商品属性参数详情")
    @GetMapping("getProductAttribute")
    @PreAuthorize("@el.check('getProductAttribute')")
    public ResultMessage pageProductAttribute(Long id){
        return productAttributeService.getProductAttribute(id);
    }
}
